#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    connect(this,&Widget::mySignal,this,&Widget::end);
    ui->checkBox->setShortcut(QKeySequence(Qt::Key_1));
    ui->checkBox_2->setShortcut(QKeySequence(Qt::Key_2));
    ui->checkBox_3->setShortcut(QKeySequence(Qt::Key_3));
    ui->pushButton->setShortcut(QKeySequence(Qt::Key_End));
}

Widget::~Widget()
{
    delete ui;
}
void Widget::end()
{
    Sleep(3000);
    Widget::close();
}

void Widget::SetLabel(QCheckBox* checkbox)
{
    QString s = "TODAY SCHEDULE:";
    bool flag = 1;
    if(ui->checkBox->isChecked())
    {    s+=ui->checkBox->text()  + ' '; flag = 0;}
    if(ui->checkBox_2->isChecked())
    {s+=ui->checkBox_2->text() + ' '; flag = 0;}
    if(ui->checkBox_3->isChecked())
    {s+=ui->checkBox_3->text() + ' '; flag = 0;}
    if(flag)s = "                    TODAY SCHEDULE:  ";
    ui->label->setText(s);
}

void Widget::on_checkBox_toggled(bool checked)
{
    SetLabel(ui->checkBox);
}
void Widget::on_checkBox_2_toggled(bool checked)
{
    SetLabel(ui->checkBox_2);
}
void Widget::on_checkBox_3_toggled(bool checked)
{
    SetLabel(ui->checkBox_3);
}

//void Widget::end()
//{
//    Sleep(1000);
//
//}

void Widget::on_pushButton_clicked()
{
    QString s("SO TODAY YOU NEED TO FINSH:\n");
    int flag = 1;
    if(ui->checkBox->isChecked())
    {    s+=ui->checkBox->text()  + ' '; flag = 0;}
    if(ui->checkBox_2->isChecked())
    {s+=ui->checkBox_2->text() + ' '; flag = 0;}
    if(ui->checkBox_3->isChecked())
    {s+=ui->checkBox_3->text() + ' '; flag = 0;}
    ui->label->setText(s);
    if(flag)
        ui->label->setText("HOW LAZY YOU ARE~");
//    emit mySignal();
}
